import json

from flask import request

from libs.error import APIException


class Success(APIException):
    code = 200
    message = 'ok'
    error_code = 0
    status = 'success'


class ParmesError(Success):
    code = 200
    message = u'无效参数'
    error_code = 1001
    status = 'error'


class Error(APIException):
    code = 500
    message = 'error'
    error_code = 0
    status = 'error'


class TooManyError(Error):
    code = 429
    message = 'Too Many Requests'
    error_code = 1010


class SetError(Error):
    message = '修改失败,请检查提交参数！'


class CountError(Error):
    message = '商品数量异常'


class LoginError(Error):
    code = 200
    message = '登录状态异常'
    error_code = 1007


class RegisterError(Error):
    message = '注册异常'
    error_code = 1008


class DeleteSuccess(Success):
    error_code = 1
    message = '删除成功'


class ServerError(Error):
    error_code = 999


class UploadFileError(Error):
    message = "文件上传失败"


class ClientTypeError(Error):
    message = 'client is invalid'
    error_code = 1006


class ParameterException(Error):
    message = 'invalid parameter'
    error_code = 1000

class BadReuest(Error):
    code = 400
    message = u'错误请求'
    error_code = 1002

class NotFound(Error):
    code = 404
    message = u'无效参数'
    error_code = 1001


class AuthFailed(Error):
    code = 401
    message = 'authorization faild'
    error_code = 1005


class Forbidden(Success):
    # code = 403
    error_code = 1004
    message = 'forbidden ,not in scope'
    status=403


class MethodError(Error):
    error_code = 1006
    code = 405
    message = 'Method Not Allowed'

class PushError(Error):
    code = 200
    error_code = 1007
    message = '请先提交基础信息！'